package com.prd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.prd.config.LoginInterceptor;
import com.prd.mapper.EntGoalStageMapper;
import com.prd.model.EntGoalStage;
import com.prd.model.LoginUser;
import com.prd.service.EntGoalStageService;
import com.prd.util.UserInfoUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EntGoalStageServiceImpl extends ServiceImpl<EntGoalStageMapper, EntGoalStage> implements EntGoalStageService {
    @Autowired
    private EntGoalStageMapper entGoalStageMapper;

    @Override
    public int insertInfo(EntGoalStage entGoalStage) {
        LoginUser loginUser = LoginInterceptor.threadLocal.get();
        BeanUtils.copyProperties(UserInfoUtil.recordInfo(loginUser.getId(), loginUser.getName(), true), entGoalStage);
        return entGoalStageMapper.insert(entGoalStage);
    }

    @Override
    public int updateInfo(EntGoalStage entGoalStage) {
        LoginUser loginUser = LoginInterceptor.threadLocal.get();
        BeanUtils.copyProperties(UserInfoUtil.recordInfo(loginUser.getId(), loginUser.getName(), false), entGoalStage);
        return entGoalStageMapper.updateById(entGoalStage);
    }

    @Override
    public List<EntGoalStage> listInfo(Long goalId) {
        LambdaQueryWrapper<EntGoalStage> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EntGoalStage::getGoalId, goalId);
        return entGoalStageMapper.selectList(queryWrapper);
    }
}
